//
//  CollectionToProductSegue.m
//  freeLance
//
//  Created by Serge Zalozniy on 5/2/13.
//  Copyright (c) 2013 Mozi Development. All rights reserved.
//

#import "CollectionToProductSegue.h"
#import "ProductViewController.h"
#import "CollectionViewController.h"

@implementation CollectionToProductSegue

-(void) perform {
    ProductViewController *productViewController = (ProductViewController *)self.destinationViewController;
    CollectionViewController *collectionViewController = (CollectionViewController *)self.sourceViewController;
	
	
    productViewController.delegate = collectionViewController;
    productViewController.view.alpha = 0.0f;
    [collectionViewController addChildViewController:productViewController];
    [collectionViewController.view addSubview:productViewController.view];
    [productViewController didMoveToParentViewController: collectionViewController];
    
    productViewController.view.transform = CGAffineTransformMakeScale(0.2, 0.2);
    
    
    [UIView animateWithDuration:0.1f animations:^{
        productViewController.view.transform = CGAffineTransformMakeScale(1.05, 1.05);
        productViewController.view.alpha = 0.6f;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.135f animations:^{
            productViewController.view.transform = CGAffineTransformMakeScale(0.97, 0.97);
            productViewController.view.alpha = 0.9f;
            collectionViewController.coverView.alpha = 0.6f;
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.17f animations:^{
                productViewController.view.transform = CGAffineTransformIdentity;
                productViewController.view.alpha = 1.0f;
                collectionViewController.coverView.alpha = 1.0f;
            }];
        }];
    }];
	productViewController.view.center = CGPointMake(430, 630);
}



@end
